package com.liu.juc.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * 带有返回值的线程
 * 1.可以有返回值
 * 2，可以抛出异常
 */
public class CallableDemo1 {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        Demo1 demo1 = new Demo1();
        // lambadb 表达式形势
//        FutureTask<String> stringFutureTask = new FutureTask<String>(()->{
//            return "12312";
//        });
        //普通模式
        FutureTask<String> stringFutureTask = new FutureTask<String>(demo1);
        new Thread(stringFutureTask).start();
        //获取返回值
        String s = stringFutureTask.get();
        System.out.println("返回值：" + s);

    }


}

class Demo1 implements Callable<String> {

    @Override
    public String call() throws Exception {
        return "312312";
    }
}
